<?php
class LoginAction extends Action {
	public function login() {
		$User = D ( 'User' );
		$user_info = $User->where ( array (
				'user_email' => $this->_post ( 'user_email' ) 
		) )->find ();
		if ($user_info) {
			if ($user_info ['user_email_verify'] == 1) {
				if ($user_info ['user_password'] == md5 ( $this->_post ( 'user_password' ) )) {
					session ( 'user', $user_info );
					cookie ( 'userCookie[' . $user_info ['user_id'] . ']', get_client_ip (), 3600 * 24 * 365 );
					$User->updateLogin ();
					redirect ( '/' );
				} else {
					$this->error ( '密码错误！' );
				}
			} else {
				$this->error ( '邮箱未验证！' );
			}
		} else {
			$this->error ( '无此用户！' );
		}
	}
	public function logout() {
		session ( 'user', NULL );
		redirect ( '/' );
	}
}